#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    vector<int> findSubstring(string s, vector<string> &words)
    {
        int m = words.size(), n = words[0].size();
        int length = s.size();
        vector<int> ans;
        for (int i = 0; i < n; ++i)
        {
            if (i + m * n > length)
            {
                break;
            }
            // 前 m 个
            unordered_map<string, int> diff;
            for (int j = 0; j < m; ++j)
            {
                diff[s.substr(i + j * m, n)]++;
            }
            for (auto &word : words)
            {
                if (--diff[word] == 0)
                {
                    diff.erase(word);
                }
            }
            if (diff.empty())
                ans.push_back(i);
            for (int j = i + n; j < length - n * m; ++j)
            {
                string word = s.substr(j, n);
                if (++diff[word] == 0)
                    diff.erase(word);
                word = s.substr(j - n, n);
                if (--diff[word] == 0)
                    diff.erase(word);
                if (diff.empty()){
                    ans.push_back(j);
                }
            }
            return ans;
        }
    }
};

int main()
{

    // system("pause");
    return 0;
}
